package com.dlc.shop.api.controller;

import com.dlc.shop.bean.dto.ThirdApiAbutmentUserDto;
import com.dlc.shop.common.response.ServerResponseEntity;
import com.dlc.shop.security.common.manager.TokenStore;
import com.dlc.shop.service.ThirdApiAbutmenService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author xxw
 * @version 1.0
 * @description: 第三方接口对接
 * @since 2023/12/15 15:10
 */
@RestController()
@RequestMapping("/p/server/user")
@AllArgsConstructor
@Tag(name = "第三方接口对接(用户端)")
public class ThirdApiAbutmentController {

    private final ThirdApiAbutmenService thirdApiAbutmenService;
    private final TokenStore tokenStore;
    /**
     * 注册用户
     */
    @PostMapping("/register")
    @Operation(summary = "注册用户")
    public ServerResponseEntity<Void> regiserUser(@RequestBody ThirdApiAbutmentUserDto thirdApiAbutmentUserDto) {
        thirdApiAbutmenService.regiserUser(thirdApiAbutmentUserDto);
        return ServerResponseEntity.success();
    }

    /**
     * 更新用户名称
     */
    @PutMapping("/update")
    @Operation(summary = "更新用户名称")
    public ServerResponseEntity<Void> updateUser(@RequestBody ThirdApiAbutmentUserDto thirdApiAbutmentUserDto) {
        thirdApiAbutmenService.updateUser(thirdApiAbutmentUserDto);
        return ServerResponseEntity.success();
    }

    /**
     * 将用户token以及过期时间同步到商城
     */
    @PostMapping("/token")
    @Operation(summary = "将用户token以及过期时间同步到商城")
    public ServerResponseEntity<Void> userTokenSync(@RequestBody ThirdApiAbutmentUserDto thirdApiAbutmentUserDto) {
        tokenStore.userTokenSync(thirdApiAbutmentUserDto);
        return ServerResponseEntity.success();
    }


    /**
     * 禁用用户
     */
    @PutMapping("/disable")
    @Operation(summary = "禁用用户")
    public ServerResponseEntity<Void> disableUser(@RequestBody ThirdApiAbutmentUserDto thirdApiAbutmentUserDto) {
        thirdApiAbutmenService.disableUser(thirdApiAbutmentUserDto.getUserId());
        return ServerResponseEntity.success();
    }
}
